﻿@using PagedList
@using PagedList.Mvc
@using TestOnlineProject.Common
@using TestOnlineProject.Models.Entities
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    ViewBag.Title = "ImportResult";
    var totalPage = 0;
}
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home", new { Area = "" }, new { })
    / @Html.ActionLink("Subjects", "Index", "Subject")
    / @Html.ActionLink("Import Subjects", "Import", "Subject")
    / Import Result
</div>
<script>
    $(document).ready(function () {
        goToPage(1);
    });
    function goToPage(page) {
        $(".subject").hide();
        $(".p" + page).show();
    }
</script>
<br />
<div class="main_nav">
    <span><a href="@Url.Content("~/Subject/Import")">
        <img src="@Url.Content("~/Images/back button.png")" /></a> </span>
</div>
<br />
<table class="table table-bordered">
    <tr>
        <td style="width: 15%">
            Import Succesful
        </td>
        <td>
            @ViewBag.Success subjects
        </td>
    </tr>
    <tr>
        <td>
            Error
        </td>
        <td>
            @ViewBag.Fail subjects
        </td>
    </tr>
</table>
<br />
<div id="list">
    <div style="min-height: 430px">
        <table class="table table-hover" style="table-layout: fixed">
            <tr>
                <th style="vertical-align: middle; width: 50px">
                    No.
                </th>
                <th style="vertical-align: middle; width: 50px">
                    Row
                </th>
                <th style="vertical-align: middle">
                    Code
                </th>
                <th style="vertical-align: middle">
                    Subject Name
                </th>
                <th style="vertical-align: middle">
                    Error
                </th>
            </tr>
            @{
                if (ViewBag.ListSubject != null)
                {
                    var subjects = (List<SubjectErrorModel>)ViewBag.ListSubject;
                    var count = 0;
                    for (int i = 0; i < subjects.Count; i++)
                    {  
                        if (!String.IsNullOrEmpty(subjects[i].Error))
                        {
                            if (count % 10 == 0)
                            {
                                if (count == 0 && totalPage == 0)
                                {
                                    totalPage = 1;
                                }
                                else if (count > 0 && count < subjects.Count)
                                {
                                    totalPage++;
                                }
                            }
                            var pageClass = "p" + totalPage;
                            count++;
                            <tr style="color: red" class="@pageClass subject">
                                <td>
                                    @count
                                </td>
                                <td>
                                    @(i + 1)
                                </td>
                                <td style="width: 15%">
                                    <span style="word-wrap: break-word">@subjects[i].Code</span>
                                </td>
                                <td style="width: 20%">
                                    <span style="word-wrap: break-word">@subjects[i].Name</span>
                                </td>
                                <td style="width: 20%">
                                    @subjects[i].Error
                                </td>
                            </tr>
                        }
                    }
                    for (int i = 0; i < subjects.Count; i++)
                    {
                        if (String.IsNullOrEmpty(subjects[i].Error))
                        {
                            if (count % 10 == 0)
                            {
                                if (count == 0 && totalPage == 0)
                                {
                                    totalPage = 1;
                                }
                                else if (count > 0 && count < subjects.Count)
                                {
                                    totalPage++;
                                }
                            }
                            var pageClass = "p" + totalPage;
                            count++;
                            <tr class="@pageClass subject">
                                <td>
                                    @count
                                </td>
                                <td>
                                    @(i + 1)
                                </td>
                                <td style="width: 15%">
                                    <span style="word-wrap: break-word">@subjects[i].Code</span>
                                </td>
                                <td style="width: 20%">
                                    <span style="word-wrap: break-word">@subjects[i].Name</span>
                                </td>
                                <td style="width: 20%">
                                    @subjects[i].Error
                                </td>
                            </tr>
                        }
                    }
                }
            }
        </table>
    </div>
    <div id="page-selection">
    </div>
    <script>
        $('#page-selection').bootpag({
            total: @totalPage,
            maxVisible: 5
        }).on("page", function (event, num) {
            goToPage(num);
            $("#page").html(num);
        });
    </script>
</div>
